package com.sky.web.app;

import com.sky.dto.SetmealDTO;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
/*

    @Autowired
    SetmealService setmealService;

    */
/**
     * 查询分类下的套餐列表
     * @param categoryId
     * @return
     *//*

    @GetMapping("/list")
    @Cacheable(value = "setmalCache",key = "'setmal_'+#categoryId")
    public Result list(@RequestParam Long categoryId){
        //封装查询条件
        SetmealDTO setmealDTO = SetmealDTO.builder()
                .categoryId(categoryId)
                .status(1)
                .build();
        //调用service查询
        List<Setmeal> list = setmealService.paramList(setmealDTO);
        //返回结果
        return Result.success(list);
    }


    */
/**
     * 套餐修改
     * @param setmealDTO
     * @return
     *//*

    @PutMapping//修改时清理本组全部缓存，因为没法怕判断是否修改了分类
    @CacheEvict(value = "setmealCache",allEntries = true)
    public Result update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success();
    }

    */
/**
     * 套餐批量删除
     * @param ids
     * @return
     *//*

    @DeleteMapping
    @CacheEvict(value = "setmealCache",allEntries = true)
    public Result deleteBatch(Long[] ids){
        setmealService.deleteBatch(ids);
        return Result.success();

    }
    @PostMapping("/status/{status}")
    @CacheEvict(value = "setmealCache",allEntries = true)
    public Result startOrStop(@PathVariable Integer status,
                              @RequestParam Long id){
        Setmeal setmeal = Setmeal.builder()
                .id(id)
                .status(status)
                .build();
        setmealService.updateStatus(setmeal);
        return Result.success();

    }
*/

}